'use strict';
import * as Koa from 'koa';
import { router, prefix } from '../middleware/router';
import { response } from '../middleware/result';
import { datadictionaryService } from '../service/datadictionary';

@prefix('datadictionary')
class DatadictionaryController {
    /**
     * 
     * @api {post} /datadictionary/queryByKey  根据key获取数据字典配置
     * @apiDescription 根据key获取数据字典配置
     * @apiName queryByKey
     * @apiParam (参数) {String} key  配置标识
     * @apiSampleRequest /datadictionary/queryByKey
     * @apiGroup datadictionary
     * @apiVersion 1.0.0
     */
    @router('/queryByKey', { method: 'post' })
    async queryByKey(ctx: Koa.Context) {
        let result = await datadictionaryService.querybyKey(ctx.request.body.key);
        response(ctx, result);
    }
    @router('/save', { method: 'post' })
    async save(ctx: Koa.Context) {
        let result = await datadictionaryService.update(ctx.request.body._id, ctx.request.body);
        response(ctx, result);
    }
    @router('/queryBycode/:key')
    async queryBycode(ctx: Koa.Context) {
        let result = await datadictionaryService.queryBycode(ctx.params.key);
        response(ctx, result);
    }
}